package cn.hznc.domain.response;

import lombok.Getter;
import lombok.Setter;
import org.springframework.http.ResponseEntity;

/**
 * 响应类
 *
 * @author xiahuanyu
 * @date 2023/3/2
 */
@Getter
@Setter
public class ResponseBody<T> extends Result {

    private T data;

    public ResponseBody() {
    }

    public ResponseBody(String code, T data, String message) {
        super(code,message);
        this.data = data;
    }

    public ResponseBody(String code, T data) {
        super(code);
        this.data = data;
    }

    public ResponseBody(String code, String message) {
        super(code,message);
    }

    public static <T> ResponseBody<T> success() {
        return success(null);
    }

    public static <T> ResponseBody<T> success(T data) {
        ResponseBody<T> response = new ResponseBody<>();
        response.setSuccess();
        response.setData(data);
        return response;
    }

    public static <T> ResponseBody<T> error(String errCode, String errMessage) {
        ResponseBody<T> response = new ResponseBody<>();
        response.setCode(errCode);
        response.setMessage(errMessage);
        return response;
    }

}
